package cn.com.dhcc.turbo.dao.stat;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import cn.com.dhcc.app.core.CM;
import cn.com.dhcc.app.core.dao.BaseDao;
import cn.com.dhcc.app.core.exception.DaoException;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;  
import cn.com.dhcc.turbo.entity.stat.ExchStatStatic;   
import cn.com.dhcc.turbo.entity.stat.wapper.ExchStatStaticRowWapper; 

@Repository
public class ExchStatStaticDao extends BaseDao {
	@SuppressWarnings("deprecation")
	private static Logger logger = Log.getExistLogger(LOGTYPE.TURBO);
	
	/**本节点接收和发送次数
	 *  @param timeType
	  * @param nt
	 * @param stat_level
	 * @return
	 * @throws DaoException
	 */
	public List<ExchStatStatic> getStLoNum(String timeType, String nt, String stat_level,String own_id) throws DaoException {
		String msg = "";
		String tableType = "";
		String mtimeModel = "";
		String ytimeModel = "";
		if(timeType.equals("month")){
			tableType = "M";
			mtimeModel = "yyyy-mm-dd";
			ytimeModel="yyyy-mm";
		}else{
			tableType = "Y";
			mtimeModel = "yyyy-mm";
			ytimeModel="yyyy";
		}
		 
		try {
			if(stat_level.equals("1")){
				String sql="select T1.*,T2.NODE_NAME as name  from ( SELECT  A .num AS sendnum, A .EXCH_TYPE, A .OWN_ID, TO_CHAR (A .NT, '"+mtimeModel+"') AS NT, "
		 + " (case when b.NUM is null then 0 else b.NUM  end ) AS revnum FROM "+ SI_TABLE(" TURBO_ST_LO_NUM_"+tableType+"")+" A LEFT JOIN "+SI_TABLE(" TURBO_ST_LO_NUM_"+tableType+"")+" b  ON A .OWN_ID = B.OWN_ID "
		+" AND A .nt = B.nt  AND A .EXCH_TYPE != B.EXCH_TYPE WHERE TO_CHAR (A .NT, '"+ytimeModel+"') = ?  AND A .EXCH_TYPE = '1' and a.stat_level=? ) t1 "
		+" , "+SI_TABLE(" TURBO_NODE_INFO ") + " t2 where T1.OWN_ID=T2.id ORDER BY T1.NT asc";
				return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(),  new Object[] {nt,stat_level}); 
			}else if(stat_level.equals("2")){
				String sql="select T1.*,T2.name  from ( SELECT  A .num AS sendnum, A .EXCH_TYPE, A .OWN_ID, TO_CHAR (A .NT, '"+mtimeModel+"') AS NT, "
						 + " (case when b.NUM is null then 0 else b.NUM  end ) AS revnum FROM "+ SI_TABLE(" TURBO_ST_LO_NUM_"+tableType+"")+" A LEFT JOIN "+SI_TABLE(" TURBO_ST_LO_NUM_"+tableType+"")+" b  ON A .OWN_ID = B.OWN_ID "
						+" AND A .nt = B.nt  AND A .EXCH_TYPE != B.EXCH_TYPE WHERE TO_CHAR (A .NT, '"+ytimeModel+"') = ?  AND A .EXCH_TYPE = '1'  and a.stat_level=? and a.own_id=? ) t1 "
						+" , "+SI_TABLE(" TURBO_DOMAIN_INFO ") + " t2 where T1.OWN_ID=T2.id ORDER BY T1.NT asc";
				return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(),  new Object[] {nt,stat_level,own_id}); 
			}else {
				String sql="select T1.*,T2.adapter_NAME as name  from ( SELECT  A .num AS sendnum, A .EXCH_TYPE, A .OWN_ID, TO_CHAR (A .NT, '"+mtimeModel+"') AS NT, "
						 + " (case when b.NUM is null then 0 else b.NUM  end ) AS revnum FROM "+ SI_TABLE(" TURBO_ST_LO_NUM_"+tableType+"")+" A LEFT JOIN "+SI_TABLE(" TURBO_ST_LO_NUM_"+tableType+"")+" b  ON A .OWN_ID = B.OWN_ID "
						+" AND A .nt = B.nt  AND A .EXCH_TYPE != B.EXCH_TYPE WHERE TO_CHAR (A .NT, '"+ytimeModel+"') = ?  AND A .EXCH_TYPE = '1' and a.stat_level=? and a.own_id=? ) t1 "
						+" , "+SI_TABLE(" turbo_adapter_info ") + " t2 where T1.OWN_ID=T2.id ORDER BY T1.NT asc";
				return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(),  new Object[] {nt,stat_level,own_id});
			}
			
		} catch (DaoException e) {
			msg = "获取数据统计失败";
			logger.error(msg, e);
			throw new DaoException(msg, e);
		}
	}
	
	
	/**本节点接收和发送频率
	 *  @param timeType
	  * @param nt
	 * @param stat_level
	 * @return
	 * @throws DaoException
	 */
	public List<ExchStatStatic> getStLoNumDtype(String timeType, String mtime, String stat_level) throws DaoException {
		String msg = "";
		String tableType = "";
		String mtimeModel = "";
		String ytimeModel = "";
		if(timeType.equals("month")){
			tableType = "M";
			mtimeModel = "yyyy-mm-dd";
			ytimeModel="yyyy-mm";
		}else{
			tableType = "Y";
			mtimeModel = "yyyy-mm";
			ytimeModel="yyyy";
		}
		String sql = "SELECT  SUM (num) AS sumnum, TO_CHAR (mtime, '"+mtimeModel+"') AS mtime,EXCH_TYPE " 
				+" FROM "+SI_TABLE("TURBO_ST_LO_NUM_DTYPE_"+tableType)+ "  WHERE  TO_CHAR (mtime, '"+ytimeModel+"') = ? and  STAT_LEVEL=? "
                +"  GROUP BY TO_CHAR (mtime, '"+mtimeModel+"') , EXCH_TYPE ";
		try {
			return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(),
					 new Object[] {mtime,stat_level});//id,time,id,time
		} catch (DaoException e) {
			msg = "获取数据统计失败";
			logger.error(msg, e);
			throw new DaoException(msg, e);
		}
	}
	 /**
		 * 内外网交换频率（月/年）
		 * @param nt 统计时间
		 * @param stat_level 统计级别： 1 节点 2 业务域 3 系统
		 * @param timeType     
		 * @param  own_id
		 * @return   
		 * @throws DaoException
		 */ 
	    public List<ExchStatStatic> getStLoNumNet(String timeType,String stat_level,String nt,String own_id) throws DaoException{
	    	String msg="";
			String tableType = "";
			String mtimeModel = "";
			String ytimeModel = ""; 
	    	try {
	    		if(timeType.equals("month")){
	    			tableType = "M";
	    			mtimeModel = "yyyy-mm-dd";
	    			ytimeModel="yyyy-mm";
	    		}else{
	    			tableType = "Y";
	    			mtimeModel = "yyyy-mm";
	    			ytimeModel="yyyy";
	    		}
	    		if(stat_level.equals("1")){ 
	    			 String sql="select  t1.*,b.node_name as name from (SELECT A.num as sendnum, A.EXCH_TYPE,  A.OWN_ID, TO_CHAR (A.NT, '"+mtimeModel+"') AS NT, (case when b.NUM is null then 0 else b.NUM  end ) as revnum "
           +"  FROM "+SI_TABLE("TURBO_ST_LO_NUM_NET_"+tableType+"")+" A   LEFT JOIN "+SI_TABLE("TURBO_ST_LO_NUM_NET_"+tableType+"")+" B "
           +" ON A.OWN_ID = B.OWN_ID  AND  A.nt = B.nt  AND A.EXCH_TYPE != B.EXCH_TYPE WHERE A.STAT_LEVEL =? "
           +" AND TO_CHAR(A.NT, '"+ytimeModel+"') = ?   and a.EXCH_TYPE='1'  ) t1 , "+SI_TABLE("TURBO_NODE_INFO ") +" B "
           +" where t1.own_id =b.id ORDER BY t1.nt asc";
	    			return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(), new Object[] {stat_level,nt}); 
	    		 }
	    		if(stat_level.equals("2")){
	    		  String sql=" select  t1.SENDNUM,T1.EXCH_TYPE,T1.OWN_ID,TO_CHAR (t1.nt, '"+mtimeModel+"') as nt,T1.REVNUM ,t2.name as name "  
	    		+ " from (SELECT A.num as sendnum,  A.EXCH_TYPE,  A.OWN_ID,  A.nt, (case when b.NUM is null then 0 else b.NUM  end )  as revnum  "  
	    		+"  FROM  "+SI_TABLE("TURBO_ST_LO_NUM_NET_"+tableType+"")+" A  "
             + " LEFT JOIN  "+SI_TABLE(" TURBO_ST_LO_NUM_NET_"+tableType+"") +"  B  ON A.OWN_ID = B.OWN_ID  AND A.nt = B.nt AND A.EXCH_TYPE != B.EXCH_TYPE "
         +"  WHERE A.STAT_LEVEL = ?  AND TO_CHAR(A.nt, '"+ytimeModel+"') = ? and a.EXCH_TYPE='1' ) t1,  "
         + SI_TABLE("TURBO_DOMAIN_INFO")+"  t2  where t1.own_id = ? and t1.own_id =t2.id order by t1.nt asc";
			    		return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(), new Object[] {stat_level,nt,own_id}); 
			    		 
	    		}else {
	    			String sql="select  t1.SENDNUM,T1.EXCH_TYPE,T1.OWN_ID,TO_CHAR (t1.nt, '"+mtimeModel+"') as nt,T1.REVNUM ,t2.adapter_name  as name "  
	    		    		+" from (SELECT A.num as sendnum,  A.EXCH_TYPE,  A.OWN_ID,  A.nt,(case when b.NUM is null then 0 else b.NUM  end ) as revnum "  
	    		    		+" FROM "+SI_TABLE("TURBO_ST_LO_NUM_NET_"+tableType+"")+" A "
	    	             + " LEFT JOIN "+SI_TABLE("TURBO_ST_LO_NUM_NET_"+tableType+"") +" B  ON A.OWN_ID = B.OWN_ID  AND A.nt = B.nt AND A.EXCH_TYPE != B.EXCH_TYPE "
	    	         +" WHERE A.STAT_LEVEL = ?  AND TO_CHAR(A.nt, '"+ytimeModel+"') = ? and a.EXCH_TYPE='1' ) t1, "
	    	         + SI_TABLE("turbo_adapter_info")+" t2  where t1.own_id =t2.id and t1.own_id =?  order by t1.nt asc";
	    			 return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(), new Object[] {stat_level,nt,own_id}); 
	    		 }
	    		
			} catch (DaoException e) {
				msg = "获取数据统计失败";
				logger.error(msg, e);
				throw new DaoException(msg, e);
			}
	    	
	    }
	    
	    
	    /**
		 * 内外网交换成功率（月/年）
		 * @param NT 统计时间
		 * @param stat_level 统计级别： 1 节点 2 业务域 3 系统
		 * @param timeType     
		 * @param  own_id
		 * @return   
		 * @throws DaoException
		 */ 
	    public List<ExchStatStatic> getStLoNetRate(String timeType,String nt,String stat_level,String own_id) throws DaoException{
	    	String msg="";
			String tableType = "";
			String mtimeModel = "";
			String ytimeModel = ""; 
	    	try {
	    		if(timeType.equals("month")){
	    			tableType = "M";
	    			mtimeModel = "yyyy-mm-dd";
	    			ytimeModel="yyyy-mm";
	    		}else{
	    			tableType = "Y";
	    			mtimeModel = "yyyy-mm";
	    			ytimeModel="yyyy";
	    		}
	    		if(stat_level.equals("1")){ 
	    			 String sql=" SELECT avg(a.num) AS NUM,a.OWN_ID,TO_CHAR (a.nt, '"+mtimeModel+"')  as nt ,b.NODE_NAME as name "
                     +" FROM "+SI_TABLE("TURBO_ST_LO_NET_RATE_"+tableType+"")+" A ," +SI_TABLE("turbo_node_info")+" B "
	                 +" WHERE a.STAT_LEVEL = ?   AND A.OWN_ID=B.id    AND TO_CHAR (a.nt, '"+ytimeModel+"')  =? " 
                     +" group BY TO_CHAR (a.nt, '"+mtimeModel+"') ,a.OWN_ID,b.NODE_NAME ORDER BY nt asc ";
	    			return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(), new Object[] {stat_level,nt}); 
	    		 }
	    		if(stat_level.equals("2")){
	    		  String sql="  SELECT  avg(a.num) as num,a.OWN_ID,TO_CHAR (a.nt, '"+mtimeModel+"')  as nt ,b.NAME  as name "
                     +" FROM "+SI_TABLE("TURBO_ST_LO_NET_RATE_"+tableType+"")+" A , "+SI_TABLE("TURBO_DOMAIN_INFO")+ " B " 
                     +" WHERE  a.STAT_LEVEL = ?   AND A.OWN_ID=B.id AND TO_CHAR (a.nt, '"+ytimeModel+"')  = ?   and a.OWN_ID= ? "  
                     + " group BY TO_CHAR (a.nt, '"+mtimeModel+"') ,a.OWN_ID,b.NAME ORDER BY nt asc  ";
			    		return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(), new Object[] {stat_level,nt,own_id}); 
			    		 
	    		}else {
	    			String sql=" SELECT avg(a.num) as num ,a.OWN_ID,TO_CHAR (a.nt, '"+mtimeModel+"')  as nt ,b.adapter_name as name "
                   +" FROM " +SI_TABLE("TURBO_ST_LO_NET_RATE_"+tableType+"")+" A ," +SI_TABLE("turbo_adapter_info") +" B "
	               +" WHERE  a.STAT_LEVEL = ?  AND A.OWN_ID=B.id  AND TO_CHAR (a.nt, '"+ytimeModel+"')  = ?  and a.OWN_ID=? "
	               +" group BY TO_CHAR (a.nt, '"+mtimeModel+"') ,a.OWN_ID,b.adapter_name order by nt asc  ";
	    			 return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(), new Object[] {stat_level,nt,own_id}); 
	    		 }
	    		
			} catch (DaoException e) {
				msg = "获取数据统计失败";
				logger.error(msg, e);
				throw new DaoException(msg, e);
			}
	    	
	    }
	    
	    
	       /**
	  		 * 与本节点交换频率最高的节点（月/年）
	  		 * @param NT 统计时间 
	  		 * @param timeType      
	  		 * @return   
	  		 * @throws DaoException
	  		 */ 
	  	    public List<ExchStatStatic> getStLoRelNodeRate(String timeType,String nt) throws DaoException{
	  	    	String msg="";
	  			String tableType = "";
	  			String mtimeModel = "";
	  			String ytimeModel = ""; 
	  	    	try {
	  	    		if(timeType.equals("month")){
	  	    			tableType = "M";
	  	    			mtimeModel = "yyyy-mm-dd";
	  	    			ytimeModel="yyyy-mm";
	  	    		}else{
	  	    			tableType = "Y";
	  	    			mtimeModel = "yyyy-mm";
	  	    			ytimeModel="yyyy";
	  	    		}
	  	    		  
	  	    	String sql=" select t1.*,t2.NODE_NAME as name  from (SELECT A.num as sendnum, A.EXCH_TYPE, A.EXCH_NODE_ID, TO_CHAR (A.NT, '"+mtimeModel+"') AS NT,(case when b.NUM is null then 0 else b.NUM  end ) as revnum  "
          +" FROM "+SI_TABLE(" TURBO_ST_LO_REL_NODE_RATE_"+tableType+"")+"  A " +" LEFT JOIN "+SI_TABLE(" TURBO_ST_LO_REL_NODE_RATE_"+tableType+"")+" B " 
          +"  ON A.EXCH_NODE_ID=B.EXCH_NODE_ID  AND  A.nt = B.nt  AND A.EXCH_TYPE != B.EXCH_TYPE "
         +" WHERE  TO_CHAR(A.NT, '"+ytimeModel+"') = ?  and a.EXCH_TYPE='1') t1, TURBO_NODE_INFO t2  where T1.EXCH_NODE_ID=T2.id  ORDER BY T1.NT ASC ";
	  	    	 return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(), new Object[] {nt }); 
	  	    	
	  			} catch (DaoException e) {
	  				msg = "获取数据统计失败";
	  				logger.error(msg, e);
	  				throw new DaoException(msg, e);
	  			}
	  	    	
	  	    }
	  	  /**
	  		 * 与本节点交换频率最高的系统（月/年）
	  		 * @param NT 统计时间 
	  		 * @param timeType      
	  		 * @return   
	  		 * @throws DaoException
	  		 */ 
	  	  public List<ExchStatStatic> getStLoRelSysRate(String timeType,String nt) throws DaoException{
	  	    	String msg="";
	  			String tableType = "";
	  			String mtimeModel = "";
	  			String ytimeModel = ""; 
	  	    	try {
	  	    		if(timeType.equals("month")){
	  	    			tableType = "M";
	  	    			mtimeModel = "yyyy-mm-dd";
	  	    			ytimeModel="yyyy-mm";
	  	    		}else{
	  	    			tableType = "Y";
	  	    			mtimeModel = "yyyy-mm";
	  	    			ytimeModel="yyyy";
	  	    		}
	  	    		  
	  	    	String sql=" select  t1.*, t2.adapter_name as name from ( select a .num as sendnum, a .exch_type, a .adapter_code, to_char (a .nt, '"+mtimeModel+"') AS NT, "
			 +" case when b.num is null then 0 else b.num end as revnum  from "+SI_TABLE("turbo_st_lo_rel_adapter_rate_"+tableType+"")+" a  left join "+SI_TABLE(" turbo_st_lo_rel_adapter_rate_"+tableType+" ")
			 +"  b on a .adapter_code = b.adapter_code and a .nt = b.nt and a .exch_type != b.exch_type where to_char (a .nt, '"+ytimeModel+"') = ? "
		     +" and a .exch_type = '1'  ) t1, "+SI_TABLE(" turbo_adapter_info") +" t2 where  t1.adapter_code = t2. adapter_code order by t1.nt asc ";
	  	    	
	  	    	 return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(), new Object[] {nt}); 
	  	    	
	  			} catch (DaoException e) {
	  				msg = "获取数据统计失败";
	  				logger.error(msg, e);
	  				throw new DaoException(msg, e);
	  			}
	  	    	
	  	    }
	  	    
	  	  
	  	/**本节点发送（按业务系统)
	  	 *  @param timeType
	  	  * @param nt 
	  	 * @return
	  	 * @throws DaoException
	  	 */
	  	public List<ExchStatStatic> getStLoNumSysSend(String timeType, String nt) throws DaoException {
	  		String msg = "";
	  		String tableType = "";
	  		String mtimeModel = "";
	  		String ytimeModel = "";
	  		if(timeType.equals("month")){
	  			tableType = "M";
	  			mtimeModel = "yyyy-mm-dd";
	  			ytimeModel="yyyy-mm";
	  		}else{
	  			tableType = "Y";
	  			mtimeModel = "yyyy-mm";
	  			ytimeModel="yyyy";
	  		}
	  		String sql = "select a .own_id, a .num, to_char (a.nt, '"+mtimeModel+"') as nt, b.adapter_name AS NAME "
          +" from "+SI_TABLE("turbo_st_lo_num_adapter_"+tableType+"")+" a, "+SI_TABLE("turbo_adapter_info")+" B "
	      +" where  a .stat_level = '3' and exch_type='1' and a .own_id = b. id and to_char (a.nt, '"+ytimeModel+"')  = ? order by nt asc";
	  		try {
	  			return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(),
	  					 new Object[] {nt});//id,time,id,time
	  		} catch (DaoException e) {
	  			msg = "获取数据统计失败";
	  			logger.error(msg, e);
	  			throw new DaoException(msg, e);
	  		}
	  	}
	  	
	  	/**本节点接收（按业务系统)
	  	 *  @param timeType
	  	  * @param nt 
	  	 * @return
	  	 * @throws DaoException
	  	 */
	  	public List<ExchStatStatic> getStLoNumSysRev(String timeType, String nt) throws DaoException {
	  		String msg = "";
	  		String tableType = "";
	  		String mtimeModel = "";
	  		String ytimeModel = "";
	  		if(timeType.equals("month")){
	  			tableType = "M";
	  			mtimeModel = "yyyy-mm-dd";
	  			ytimeModel="yyyy-mm";
	  		}else{
	  			tableType = "Y";
	  			mtimeModel = "yyyy-mm";
	  			ytimeModel="yyyy";
	  		}
	  		String sql = "select a .own_id, a .num, to_char (a.nt, '"+mtimeModel+"') as nt, b.adapter_name as name "
          +" from "+SI_TABLE("turbo_st_lo_num_adapter_"+tableType+"")+" a, "+SI_TABLE("turbo_adapter_info")+" B "
	      +" where  a .stat_level = '3' and exch_type='2' and a .own_id = b. id and to_char (a.nt, '"+ytimeModel+"')  = ? order by nt asc";
	  		try {
	  			return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(),
	  					 new Object[] {nt});//id,time,id,time
	  		} catch (DaoException e) {
	  			msg = "获取数据统计失败";
	  			logger.error(msg, e);
	  			throw new DaoException(msg, e);
	  		}
	  	}
	  	/**本节点发送（按数据分类)
	  	 *  @param timeType
	  	  * @param nt 
	  	  * @param stat_level
	  	  * @param  own_id
	  	  * EXCH_TYPE =1 发送
	  	 * @return 
	  	 * @throws DaoException
	  	 */
		public List<ExchStatStatic> getStLoNumDtypeSend(String timeType, String nt,String stat_level,String own_id) throws DaoException {
	  		String msg = "";
	  		String tableType = "";
	  		String mtimeModel = "";
	  		String ytimeModel = "";
	  		if(timeType.equals("month")){
	  			tableType = "M";
	  			mtimeModel = "yyyy-mm-dd";
	  			ytimeModel="yyyy-mm";
	  		}else{
	  			tableType = "Y";
	  			mtimeModel = "yyyy-mm";
	  			ytimeModel="yyyy";
	  		} 
	  		try {
	  		   if(stat_level.equals("1")){
	  			 String sql = "select  a .exch_type, a .data_code, a .stat_level, a .num, b.data_name as name ,to_char (a.nt, '"+mtimeModel+"') as nt "
	  		              +" from "+SI_TABLE("turbo_st_lo_num_dtype_"+tableType+"")+" a, "+SI_TABLE("turbo_data_category")+" b where to_char (a .nt, '"+ytimeModel+"') = ? "
	  		              + " and a .stat_level = ?  and a .exch_type = '1'   and a.data_code = b.data_code";
		  			return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(),
		  					 new Object[] {nt,stat_level}); 
	  		   }else if(stat_level.equals("2")){
	  	String sql = "select c. name as adapter_name, a .exch_type, a .data_code, a .stat_level, a .num, b.data_name as name, to_char (a .nt, '"+mtimeModel+"') AS nt "
        +" from "+SI_TABLE("turbo_st_lo_num_dtype_"+tableType+"")+" a, "+SI_TABLE("turbo_data_category")+" b, "+SI_TABLE("turbo_domain_info")+" c where  "
        +" to_char (a .nt, '"+ytimeModel+"') = ?  and a .stat_level =? and a .own_id = ? and a .own_id = c. id  and a .exch_type = '1' and a .data_code = b. data_code ";
		  			return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(),
		  					 new Object[] {nt,stat_level,own_id}); 
	  		   }
	  		   else{
	  			 String sql = "select c.adapter_name as adapter_name, a .exch_type, a .data_code, a .stat_level, a .num, b.data_name as name , to_char (a .nt, '"+mtimeModel+"') as nt "
        +" from "+SI_TABLE("turbo_st_lo_num_dtype_"+tableType+"")+" a, " +SI_TABLE("turbo_data_category")+" B, "+SI_TABLE("turbo_adapter_info")+" c where to_char (a .nt, '"+ytimeModel+"') = ? "
       +" and a .stat_level = ? and  a .own_id = ? and a .own_id = c. id  and a .exch_type = '1'  and a .data_code = b. data_code";
		  			return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(),
		  					 new Object[] {nt,stat_level,own_id}); 
	  		   }
	  		} catch (DaoException e) {
	  			msg = "获取数据统计失败";
	  			logger.error(msg, e);
	  			throw new DaoException(msg, e);
	  		}
	  	}
		
		/**本节点接收（按数据分类)
	  	 *  @param timeType
	  	  * @param nt 
	  	  * @param stat_level
	  	  * @param  own_id
	  	  * EXCH_TYPE=2 接收 
	  	 * @return  
	  	 * @throws DaoException
	  	 */
		public List<ExchStatStatic> getStLoNumDtypeRev(String timeType, String nt,String stat_level,String own_id) throws DaoException {
	  		String msg = "";
	  		String tableType = "";
	  		String mtimeModel = "";
	  		String ytimeModel = "";
	  		if(timeType.equals("month")){
	  			tableType = "M";
	  			mtimeModel = "yyyy-mm-dd";
	  			ytimeModel="yyyy-mm";
	  		}else{
	  			tableType = "Y";
	  			mtimeModel = "yyyy-mm";
	  			ytimeModel="yyyy";
	  		} 
	  		try {
	  			if(stat_level.equals("1")){
	  				String sql = "SELECT  A .EXCH_TYPE, A .data_code, A .STAT_LEVEL, A .num, B.DATA_NAME as name ,TO_CHAR (A.nt, '"+mtimeModel+"') AS nt "
              +" FROM "+SI_TABLE("TURBO_ST_LO_NUM_DTYPE_"+tableType+"")+" A, "+SI_TABLE("TURBO_DATA_CATEGORY")+" B WHERE TO_CHAR (A .nt, '"+ytimeModel+"') = ? "
              + " AND A .STAT_LEVEL = ?  AND A .EXCH_TYPE = '2'  AND A .data_code = B. data_code";
		  			return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(),
		  					 new Object[] {nt,stat_level});
	  			} else if(stat_level.equals("2")){
	  				String sql = "SELECT c. NAME AS adapter_name, A .EXCH_TYPE, A .data_code, A .STAT_LEVEL, A .num, B.DATA_NAME as name, TO_CHAR (A .nt, '"+mtimeModel+"') AS nt "
        +" FROM "+SI_TABLE("TURBO_ST_LO_NUM_DTYPE_"+tableType+"")+" a, "+SI_TABLE("TURBO_DATA_CATEGORY")+" B, "+SI_TABLE("TURBO_DOMAIN_INFO")+" C WHERE  "
        +" TO_CHAR (A .nt, '"+ytimeModel+"') = ?  AND A .STAT_LEVEL =? and A .OWN_ID = ? AND A .own_id = c. ID  AND A .EXCH_TYPE = '2' AND A .data_code = B. data_code ";
		  			return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(),
		  					 new Object[] {nt,stat_level,own_id});
	  			} else{
	  				String sql = "SELECT c.adapter_NAME AS adapter_name, A .EXCH_TYPE, A .data_code, A .STAT_LEVEL, A .num, B.DATA_NAME as name , TO_CHAR (A .nt, '"+mtimeModel+"') AS nt "
	  				        +" FROM "+SI_TABLE("TURBO_ST_LO_NUM_DTYPE_"+tableType+"")+" A, " +SI_TABLE("TURBO_DATA_CATEGORY")+" B, "+SI_TABLE("turbo_adapter_info")+" C WHERE TO_CHAR (A .nt, '"+ytimeModel+"') = ? "
	  				       +" AND A .STAT_LEVEL = ? and  A .OWN_ID = ? AND A .own_id = c. ID  AND A .EXCH_TYPE = '2'  AND A .data_code = B. data_code";
		  			return CM.getDao().list("获取数据统计", sql, new ExchStatStaticRowWapper(),
		  					 new Object[] {nt,stat_level,own_id});
	  			}
	  			
	  		} catch (DaoException e) {
	  			msg = "获取数据统计失败";
	  			logger.error(msg, e);
	  			throw new DaoException(msg, e);
	  		}
	  	}
	  	
	    /**
	     *获取系统信息
	     *
	     */
	    public List<ExchStatStatic> getSysInfos() throws  DaoException{
	    	String msg=""; 
	    	try {
	    		String sql="SELECT adapter_name ,id  from "+SI_TABLE(" TURBO_SYS_INFO ");
	    		return CM.getDao().list("获取系统信息", sql,  new ExchStatStaticRowWapper(), new Object[] {});
			} catch (Exception e) {
				msg = "获取系统信息失败";
				logger.error(msg, e);
				throw new DaoException(msg, e);
			}
	    	
	    }
	    
	    /**
	     *获取系统信息
	     *
	     */
	    public ExchStatStatic getSysNameInfos(String own_id) throws  DaoException{
	    	String msg=""; 
	    	try {
	    		String sql="SELECT adapter_NAME as name,id  from "+SI_TABLE(" TURBO_adapter_INFO ")+" where id=?"; 
			 return CM.getDao().get("获取系统信息", sql, new ExchStatStaticRowWapper(), new Object[] {own_id});
	    	} catch (Exception e) {
				msg = "获取系统信息失败";
				logger.error(msg, e);
				throw new DaoException(msg, e);
			}
	    	
	    }
	    
	    /**
	     *获取业务域信息
	     *
	     */
	    public ExchStatStatic getDomNameInfos(String own_id) throws  DaoException{
	    	String msg=""; 
	    	try {
	    		String sql="SELECT  name,id  from "+SI_TABLE("TURBO_DOMAIN_INFO")+" where id=?"; 
			 return CM.getDao().get("获取业务域信息", sql, new ExchStatStaticRowWapper(), new Object[] {own_id});
	    	} catch (Exception e) {
				msg = "获取业务域信息失败";
				logger.error(msg, e);
				throw new DaoException(msg, e);
			}
	    	
	    }
	    
	    /**
	     *获取业务域信息
	     *
	     */
	    public List<ExchStatStatic> getDomInfos() throws  DaoException{
	    	String msg=""; 
	    	try {
	    		String sql="SELECT NAME ,id  from "+SI_TABLE(" TURBO_DOMAIN_INFO ");
	    		return CM.getDao().list("获取节点信息", sql,  new ExchStatStaticRowWapper(), new Object[] {});
			} catch (Exception e) {
				msg = "获取节点信息失败";
				logger.error(msg, e);
				throw new DaoException(msg, e);
			}
	    	
	    }
	     
	 
}
